﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using EIS.ClientUtility;
using EIS.Data;
using EIS.DatabaseHelper;
using EIS.Obj;
using EIS.ServerAdapter;


namespace EIS.ClientRoutineJob
{
    public class FetchTransactionData
    {
        public int Execute()
        {
            if (GlobalVariable.Instance.FecthingData == false)
            {
                GlobalVariable.Instance.FecthingData = true;

                int totalNumber = 0;
                try
                {
                    var func = GlobalVariable.Instance.ActiveFunctionID;

                    foreach (var funcId in func)
                    {
                        int i = new FunctionData(funcId).LoadFromServer();
                        totalNumber = totalNumber + i;
                    }
                }
                catch (Exception ex)
                {
                    GlobalVariable.Instance.FecthingData = false;
                    ShowErrorMessageBox.Show(ex.InnerException == null ? ex.Message : ex.InnerException.Message);
                }
                GlobalVariable.Instance.FecthingData = false;
                return totalNumber;
            }
            else
            {
                return 0;
            }
        }
    }
}

